<?php
/**
 * Created by PhpStorm.
 * User: Administrator
 * Date: 2016/4/25 0025
 * Time: 下午 1:22
 */namespace Api\Controller;

class MemberCircleController extends ApiController{

    public function __construct(){
        parent::__construct();
        if(!$this->user_info){
            $this->error($this->error,999);
            exit;
        }
    }

    //我加入的圈子
    public function my_join(){
        //获取到创建的圈子
        $where = array();
        $where['uid'] = $this->user_info['id'];
        $my_circles = M('Circle')->where($where)->select();

        //获取到加入的圈子
        $where = array();
        $where['A.uid'] = $this->user_info['id'];
        $where['A.role'] = array('neq', '圈主');
        $joined_circles = M('CircleMembers')->alias('A')->field('A.*,B.username as qz,B.name as circle_name,B.face')
            ->join(C('DB_PREFIX').'circle B ON B.id = A.cid','left')
            ->where($where)->select();
        if(!empty($my_circles)){
            foreach($my_circles as $k=>$v){
                $my_circles[$k]['createTime'] = date('Y-m-d', $v['create_time']);
            }
        }
        if(!empty($joined_circles)){
            foreach ($joined_circles as $k=>$v){
                $joined_circles[$k]['createTime'] = date('Y-m-d', $v['create_time']);
                $joined_circles[$k]['expirationTime'] = calcu_time($v['expiration_time']);
                $joined_circles[$k]['joinTime'] = date('Y-m-d', $v['join_time']);
            }
        }

        $return = array(
            'joined_circles'   =>  $joined_circles,
            'my_circles'=>  $my_circles,
        );

        $this->success($return,'');
    }

}